package com.tienon.message.thread.task;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.tienon.message.entity.Raw_msg_item;
import com.tienon.message.mapper.Raw_msg_itemMapper;
import com.tienon.message.thread.LoadRawMsgItemThread;

/**
 * @author zn
 * 消息接入重试类
 */
@Component
public class ReLoadRawMsgItemTask {
	@Resource
	private Raw_msg_itemMapper raw_msg_itemMapper;
	
	Logger log = Logger.getLogger(LoadRawMsgItemThread.class);
	/**
	 * 查询表Raw_Msg_Item数据，比且进行数据处理
	 * @return Raw_Msg_Item的集合
	 */
	@Transactional
	public Object dealSendRaw_Msg_Item(){
		List<Raw_msg_item> listItems = raw_msg_itemMapper.selectByState();
		log.info("listItems的大小:"+listItems.size()+",当前线程(进入处理):"+Thread.currentThread().getName());
		if(0 == listItems.size()){
			return null;
		}
		for(Raw_msg_item raw_msg_item : listItems){
			log.info("序列号："+raw_msg_item.getSerail()+",当前线程："+Thread.currentThread().getName()+",批次号："+raw_msg_item.getBatId());
			//LoadSendMsgTasks.loadAppSendMsgTask(raw_msg_item);//有错 ，应该传入发送原始表对象
			raw_msg_item.setState(2);
			raw_msg_item.setSendTimes(raw_msg_item.getSendTimes() + 1);
			raw_msg_item.setSendTime(new Date());
			raw_msg_itemMapper.updateByPrimaryKey(raw_msg_item);
		}
		return listItems;
	}
}
